package com.dahouzi.commom;

/**
 * @author Kejianlong
 * @date 2016年8月10日 上午11:00:00
 */
public class Feedback {
	/*
	 * 2xx (成功) 3xx (重定向) 4xx(请求错误) 5xx(服务器错误)
	 */
	// 状态码定义

	// 成功返回
	public static final int REQUEST_OK = 200;
	public static final int REQUEST_ERROR = 400;
	// session 失效
	public static final int NO_AUTHORIZATION = 300;
	// 未登录或超时
	public static final int OFF_LINE = 401;


	public static final String MSG_QUERY_SUCCESS = "查询成功";
	public static final String MSG_UPDATE_SUCCESS = "修改成功";
	public static final String MSG_SAVE_SUCCESS = "保存成功";
	public static final String MSG_DELETE_SUCCESS = "删除成功";

	public static final String MSG_QUERY_ERROR = "查询失败";
	public static final String MSG_UPDATE_ERROR = "修改失败";
	public static final String MSG_SAVE_ERROR = "保存失败";
	public static final String MSG_DELECT_ERROR = "删除失败";

	public static final String MSG_ERROR = "数据请求发生错误，请稍候重试";
	// 状态吗
	private int code;
	// 信息
	private String msg;
	// 返回结果数据
	private Object result;

	public Feedback() {
	}

	public Feedback(int code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	public Feedback(int code, String msg, Object result) {
		this.code = code;
		this.msg = msg;
		this.result = result;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getResult() {
		return result;
	}

	public void setResult(Object result) {
		this.result = result;
	}

	public static Feedback success() {
		return new Feedback(REQUEST_OK, "");
	}

	public static Feedback success(String msg) {
		return new Feedback(REQUEST_OK, msg);
	}

	public static Feedback success(String msg, Object result) {
		return new Feedback(REQUEST_OK, msg, result);
	}

	public static Feedback error(String msg) {
		return new Feedback(REQUEST_ERROR, msg);
	}

	public static Feedback error(String msg, Object result) {
		return new Feedback(REQUEST_ERROR, msg, result);
	}

	public static Feedback error(int code, String msg, Object result) {
		return new Feedback(code, msg, result);
	}

	public boolean isSuccess() {
		if (code == REQUEST_OK) {
			return true;
		} else {
			return false;
		}
	}
}
